//
//  HomeThreeCell.m
//  Cat
//
//  Created by lushitong on 2019/1/27.
//  Copyright © 2019年 lushitong. All rights reserved.
//

#import "HomeThreeCell.h"
#import "FLImageView.h"

#import "HomePriorityInfo.h"
#import "WebViewController.h"

@interface HomeThreeCell()<FLImageViewDelegate>

@property (nonatomic, strong) FLImageView *image1;
@property (nonatomic, strong) FLImageView *image2;
@property (nonatomic, strong) FLImageView *image3;
@property (nonatomic, strong) NSArray *recCommArray;
@property (nonatomic, strong) UIView *backView;
@property (nonatomic, strong) UIView *backView2;
@property (nonatomic, strong) UIView *bottomView;

@end

@implementation HomeThreeCell

- (void)setRecArray:(NSArray *)array {
	_recCommArray = array;
	RecommendsModel *model1 = [array safeObjectAtIndex:0];
	RecommendsModel *model2 = [array safeObjectAtIndex:1];
	RecommendsModel *model3 = [array safeObjectAtIndex:2];
	
	[self.image1 setImageUrl:[NSURL URLWithString:model1.imgUrl] size:CGSizeMake((ScreenWidth - kQKFitModuleDecimal(32) )/ 2, kQKFitModuleDecimal(181)) cornerRadius:0.0];
	[self.image2 setImageUrl:[NSURL URLWithString:model2.imgUrl] size:CGSizeMake((ScreenWidth - kQKFitModuleDecimal(32) )/ 2, kQKFitModuleDecimal(181)/2) cornerRadius:0.0];
	[self.image3 setImageUrl:[NSURL URLWithString:model3.imgUrl] size:CGSizeMake((ScreenWidth - kQKFitModuleDecimal(32) )/ 2, kQKFitModuleDecimal(181)/2) cornerRadius:0.0];
}

- (instancetype)initWithFrame:(CGRect)frame {
	if (self = [super initWithFrame:frame]) {
		self.contentView.backgroundColor = COLOR_WITH_HEX(0xFAFAFA);
		[self loadALlSubView];
	}
	return self;
}

- (void)loadALlSubView{
	/*
	
	 */
	[self.contentView addSubviews:@[self.backView,self.backView2,self.bottomView]];
	[self.backView2 addSubviews:@[self.image1,self.image2,self.image3]];
	
	[self.image1 mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(self.contentView.mas_left).offset(kQKFitModuleDecimal(16.0));
		make.top.equalTo(self.contentView.mas_top).offset(kQKFitModuleDecimal(24.0));
		make.size.equalTo(CGSizeMake((ScreenWidth - kQKFitModuleDecimal(32) )/ 2, kQKFitModuleDecimal(181)));
	}];
	
	[self.image2 mas_makeConstraints:^(MASConstraintMaker *make) {
		make.size.equalTo(CGSizeMake((ScreenWidth - kQKFitModuleDecimal(32) )/ 2, kQKFitModuleDecimal(181)/ 2));
		make.top.equalTo(self.image1.mas_top);
		make.left.equalTo(self.image1.mas_right);
	}];
	
	
	[self.image3 mas_makeConstraints:^(MASConstraintMaker *make) {
		make.size.equalTo(CGSizeMake((ScreenWidth - kQKFitModuleDecimal(32) )/ 2, kQKFitModuleDecimal(181)/ 2));
		make.top.equalTo(self.image2.mas_bottom);
		make.left.equalTo(self.image1.mas_right);
	}];
	
	[self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(self.image1.mas_left);
		make.top.equalTo(self.image1.mas_top);
		make.right.equalTo(self.image2.mas_right);
		make.bottom.equalTo(self.image1.mas_bottom);
	}];
	
	[self.backView2 mas_makeConstraints:^(MASConstraintMaker *make) {
		make.edges.equalTo(self.backView);
	}];
	
	[self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.and.right.and.bottom.equalTo(self.contentView);
		make.height.equalTo(kQKFitModuleDecimal(8.0));
	}];
}

- (void)clickImageView:(FLImageView *)headView {
	RecommendsModel *model = [[RecommendsModel alloc] init];
	if ([headView isEqual:self.image1]) {
		model = [self.recCommArray safeObjectAtIndex:0];
	} else if ([headView isEqual:self.image2]) {
		model = [self.recCommArray safeObjectAtIndex:1];
	} else {
		model = [self.recCommArray safeObjectAtIndex:2];
	}
	WebViewController *web = [[WebViewController alloc] init];
	web.URL = model.targetUrl;
	[self.currentNavigationController pushViewController:web animated:YES];
}

#pragma mark----- lazy inti -----

- (FLImageView *)image1 {
	if (!_image1) {
		_image1 = [[FLImageView alloc] init];
		_image1.delegate = self;
	}
	return _image1;
}

- (FLImageView *)image2 {
	if (!_image2) {
		_image2 = [[FLImageView alloc] init];
		_image2.delegate = self;
	}
	return _image2;
}

- (FLImageView *)image3 {
	if (!_image3) {
		_image3 = [[FLImageView alloc] init];
		_image3.delegate = self;
	}
	return _image3;
}

- (UIView *)backView {
	if (!_backView) {
		_backView = [[UIView alloc] init];
		_backView.layer.shadowColor = COLOR_WITH_HEX_A(0x000000, 0.8).CGColor;
		_backView.layer.shadowOffset = CGSizeZero;
		_backView.layer.shadowOpacity = 0.8; // 阴影透明度，默认0
		_backView.layer.shadowRadius = kQKFitModuleDecimal(4);    // 阴影半径，默认3
		_backView.layer.cornerRadius = kQKFitModuleDecimal(6);
	}
	return _backView;
}

- (UIView *)backView2 {
	if (!_backView2) {
		_backView2 = [[UIView alloc] init];
		_backView2.layer.cornerRadius = kQKFitModuleDecimal(6);
		_backView2.layer.masksToBounds = YES;
	}
	return _backView2;
}

- (UIView *)bottomView {
	if (!_bottomView) {
		_bottomView = [[UIView alloc] init];
		_bottomView.backgroundColor = COLOR_WITH_HEX(0xF3F3F3);
	}
	return _bottomView;
}

@end
